﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Nop.Core;
using Nop.Core.Data;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Media;
using Nop.Core.Infrastructure;
using Nop.Data;
using Nop.Plugin.Resources.Client.Domain;
using Nop.Services.Catalog;
using Nop.Services.Configuration;
using Nop.Services.Events;
using Nop.Services.Media;
using Nop.Services.Seo;

namespace Nop.Plugin.Resources.Client.Services
{
    public class ResPictureService : PictureService
    {
        #region Fields

        private readonly IDataProvider _dataProvider;
        private readonly IDbContext _dbContext;
        private readonly IEventPublisher _eventPublisher;
        private readonly INopFileProvider _fileProvider;
        private readonly IProductAttributeParser _productAttributeParser;
        private readonly IRepository<Picture> _pictureRepository;
        private readonly IRepository<PictureUrl> _pictureUrlRepository;
        private readonly IRepository<ProductPicture> _productPictureRepository;
        private readonly ISettingService _settingService;
        private readonly IUrlRecordService _urlRecordService;
        private readonly IWebHelper _webHelper;
        private readonly MediaSettings _mediaSettings;

        public ResPictureService(IDataProvider dataProvider,
            IDbContext dbContext,
            IEventPublisher eventPublisher,
            INopFileProvider fileProvider,
            IProductAttributeParser productAttributeParser,
            IRepository<Picture> pictureRepository,
            IRepository<PictureBinary> pictureBinaryRepository,
            IRepository<ProductPicture> productPictureRepository,
            IRepository<PictureUrl> pictureUrlRepository,
            ISettingService settingService,
            IUrlRecordService urlRecordService,
            IWebHelper webHelper,
            MediaSettings mediaSettings) : base(dataProvider,
                dbContext,
                eventPublisher,
                fileProvider,
                productAttributeParser,
                pictureRepository,
                pictureBinaryRepository,
                productPictureRepository,
                settingService,
                urlRecordService,
                webHelper,
                mediaSettings)
        {
            _dataProvider = dataProvider;
            _dbContext = dbContext;
            _eventPublisher = eventPublisher;
            _fileProvider = fileProvider;
            _productAttributeParser = productAttributeParser;
            _pictureRepository = pictureRepository;
            _pictureUrlRepository = pictureUrlRepository;
            _productPictureRepository = productPictureRepository;
            _settingService = settingService;
            _urlRecordService = urlRecordService;
            _webHelper = webHelper;
            _mediaSettings = mediaSettings;

        }

        #endregion

        private ResSettings Settings { get => _settingService.LoadSetting<ResSettings>(); }


        public override bool StoreInDb
        {
            get
            {
                if (Settings.Enable)
                {
                    return false;
                }
                else
                {
                    return base.StoreInDb;
                }

            }
            set
            {
                if (Settings.Enable)
                {
                    throw new Exception("启用资源服务器的情况下不支持");
                }
                else
                {
                    base.StoreInDb = value;
                }

            }
        }


        protected override void DeletePictureThumbs(Picture picture)
        {

        }

        protected override string GetThumbLocalPath(string thumbFileName)
        {

        }


        protected override string GetThumbUrl(string thumbFileName, string storeLocation = null)
        {

        }

        protected override bool GeneratedThumbExists(string thumbFilePath, string thumbFileName)
        {

        }

        protected override void SaveThumb(string thumbFilePath, string thumbFileName, string mimeType, byte[] binary)
        {

        }
    }
}
